<template>
    <div>
        <div class="search_style">
            <div>
                <Form>
                    <FormItem label="用户名" :label-width="80">
                        <Input v-model="username" placeholder="请输入用户名"></Input>
                    </FormItem>
                </Form>
            </div>
            <div class="button_style">
                <Button type="primary" @click="sub">查询</Button>
            </div>
        </div>
        <div>
            <Card style="height: 100%">
                <p slot="title">
                    <a>
                        <Icon type="gear-a"></Icon>
                        推荐关系图</a>
                </p>
                <Tree :data="list" :load-data="getDown"></Tree>
            </Card>
        </div>
    </div>
</template>

<script>
    export default {
        name: "downList",
        data() {
            return {
                list:[],
                username:'admin',
                baseData: [{
                    title: 'parent 1',
                    children: [{
                        title: 'parent 1-0',
                        children: [{
                            title: 'leaf',
                        }, {
                            title: 'leaf',
                        }]
                    }, {
                        title: 'parent 1-1',
                        children: [{
                            title: 'abc',
                        }]
                    }]
                }]
            }
        },

        activated() {
            // this.init()
            if(this.$route.query.isEdit){
                this.username = this.$route.query.username
                this.sub()
            }

        },
        methods: {
            // init(){
            //     this.getJsonData('User/getInivt',).then((res)=>{
            //         this.list = res.user.map((value)=>{
            //             value.children=[]
            //             value.isShow = false
            //             return value
            //         })
            //     })
            // },
            sub(){
                this.getJsonData('User/getInivt',{
                    username: this.username
                }).then((res)=>{
                    this.list = res.user;
                })
            },
            getDown(node, callback) {
                this.getJsonData('User/getInivtDown',{
                    username: node.title
                }).then((res)=>{
                   callback(res.user);
                })
            }
        }
    }
</script>

<style lang="less">
    @import "./downList";

</style>
